package com.lym.action;

import javax.annotation.Resource;

import com.lym.model.User;
import com.lym.service.UserService;
import com.lym.vo.UserInfo;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("serial")
public class UserAction extends ActionSupport implements ModelDriven<UserInfo> {
	private UserService userService;
	private UserInfo userInfo = new UserInfo();
	private User user;
	private int verification;

	public String registerInput() {
		this.verification = (int) (Math.random() * 9000 + 1000);
		return "registerInput";
	}

	public String loginInput() {
		this.verification = (int) (Math.random() * 9000 + 1000);
		return "loginInput";
	}

	public String register() {
		this.user = new User();
		this.user.setUsername(this.userInfo.getUsername());
		this.user.setPassword(this.userInfo.getPassword());
		this.user.setEmail(this.userInfo.getEmail());
		this.userService.add(this.user);
		return "success";
	}

	public String login() {
		this.user = new User();
		this.user.setUsername(this.userInfo.getUsername());
		this.user.setPassword(this.userInfo.getPassword());
		return "success";
	}

	public UserInfo getModel() {
		return this.userInfo;
	}

	public UserService getUserService() {
		return this.userService;
	}

	@Resource(name = "userService")
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public UserInfo getUserInfo() {
		return this.userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public int getVerification() {
		return this.verification;
	}

	public void setVerification(int verification) {
		this.verification = verification;
	}
}
